new Vue({
  el: '#app',
  data: {
    form: {
      username: '',
      mobile: '',
      password: '',
      captcha: '',
      tjcode: '',
      paypwd: ''
    },
    send: false,
    loading: true,
    countDownTime: 60,
    countDownTimer: null,
    rules: rules,
  },
  mounted () {
    this.loading = false;
    this.form.tjcode = $utils.query('id')
  },
  methods: {
    onClickLeft: function () {
      history.go(-1)
    },
    onSubmit(formName) {
      this.$refs[formName].validate(async (valid) => {
        if (!valid) { return false; }
        let res = await $http.post('/api/user/register', this.form)
        if (res.data.code != 1) { return this.$toast(res.data.msg) }

        this.$toast.success({
          message: '注册成功',
          onClose: function () { window.location.href = './login.html' }
        })
      })

    },
    getCaptcha() {
      if(this.send) { return;}
      this.send = true;
      this.countDownTimer = setInterval(this.countDown, 1000)
    },
    countDown() {
      if(this.countDownTime <= 0) {
        this.send = false
        this.countDownTime = 60
        clearInterval(this.countDownTimer)
      }
      
      this.countDownTime--
    }
  }
})